package com.bikes.mileagetracker.entity

import android.database.sqlite.SQLiteDatabase
import com.bikes.mileagetracker.orm.BaseDataBaseHelper
import com.bikes.mileagetracker.orm.DbCreator

class MileageTrackerDbCreator : DbCreator {
    override fun getDataBaseVersion(): Int {
        return 1
    }

    override fun getDataBaseName(): String {
        return "mt"
    }

    override fun onCreate(db: SQLiteDatabase) {
        super.onCreate(db)
        buildDatabase(db, true)
    }

    override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
        super.onUpgrade(db, oldVersion, newVersion)
        buildDatabase(db, false)
    }

    private fun buildDatabase(db: SQLiteDatabase, force:Boolean){
        BaseDataBaseHelper.createTable(db, UserEntity::class.java, force)
        BaseDataBaseHelper.createTable(db, TrackingEntity::class.java, force)
        BaseDataBaseHelper.createTable(db, LocationEntity::class.java, force)
    }

}